package com.jp.knowledge.my.adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.view.View;
import android.widget.TextView;

import com.jp.knowledge.R;
import com.jp.knowledge.my.base.RecycleVAdapter;
import com.jp.knowledge.my.base.RecycleVHolder;
import com.jp.knowledge.my.model.OrderDetailScheduleModel;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by 528787067@qq.com on 2017/5/5.
 */

public class OrderDetailScheduleAdapter extends RecycleVAdapter<OrderDetailScheduleModel> {

    private SimpleDateFormat dateFormat;
    public OrderDetailScheduleAdapter(Context context, @NonNull List<OrderDetailScheduleModel> list) {
        super(context, list);
        this.dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
    }

    @Override
    public int getLayoutId(int viewType) {
        return R.layout.item_order_detail_schedule;
    }

    @Override
    public void onBind(RecycleVHolder holder, int position) {
        OrderDetailScheduleModel data = getData(position);
        if(position == mList.size() - 1){
            holder.get(R.id.order_schedule_dot).setVisibility(View.GONE);
            holder.get(R.id.order_schedule_dot_select).setVisibility(View.VISIBLE);
        } else{
            holder.get(R.id.order_schedule_dot).setVisibility(View.VISIBLE);
            holder.get(R.id.order_schedule_dot_select).setVisibility(View.INVISIBLE);
        }

        holder.setTextView(R.id.order_schedule_time, dateFormat.format(data.getCreatetime()));

        int orderState = data.getOrderState();
        TextView orderStateTv = holder.getTextView(R.id.order_schedule_state);
        orderStateTv.setVisibility(View.VISIBLE);
        if(orderState == 1){
            orderStateTv.setText("待付款");
        } else if(orderState == 2){
            orderStateTv.setText("待完成");
        } else if(orderState == 3){
            orderStateTv.setText("已取消");
        } else if(orderState == 4){
            orderStateTv.setText("待收货");
        } else if(orderState == 5){
            orderStateTv.setText("已完成");
        } else if(orderState == 6){
            orderStateTv.setText("售后中");
        } else{
            orderStateTv.setVisibility(View.GONE);
        }

        TextView scheduleRemarks = holder.get(R.id.order_schedule_remarks);
        if(data.getRemarks() == null || data.getRemarks().trim().length() == 0){
            scheduleRemarks.setVisibility(View.GONE);
        } else{
            scheduleRemarks.setVisibility(View.VISIBLE);
            scheduleRemarks.setText(data.getRemarks());
        }
    }
}
